from kafka import *

consumer_path = '../../trans_file/consumer_file/'


def recordMsg():
    consumer = KafkaConsumer('testPython',
                             bootstrap_servers=['master:9092'])
    for message in consumer:
        write_file(message.value)
        print("%s:%d:%d: key=%s value=%s" %
              (message.topic, message.partition,
               message.offset, message.key,
               message.value))
        print("成功")
    pass


def write_file(bytes):
    file_name = 'after_trans123.jpg'
    with open(consumer_path+file_name, "wb") as w:
        w.write(bytes)



if __name__ == '__main__':
    recordMsg()